package org.example.mapper;

import org.example.dto.UserDto;
import org.example.po.User;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

import java.util.List;

/**
 * @author liyishan
 * @date 2023/6/6 16:41
 * @apiNote
 */
@Mapper
public interface User2Mapper {


    //yyyy-MM-dd HH:mm:ss

    @Mappings({
            @Mapping(source = "pwd",target = "password"),
            @Mapping(target = "birthformat", expression = "java(org.apache.commons.lang3.time.DateFormatUtils.format(user.getBirth(),\"yyyy-MM-dd\"))")
    })
    public UserDto userToUserDto(User user);


    @Mappings({
            @Mapping(source = "pwd",target = "password"),
            @Mapping(target = "birthformat", expression = "java(org.apache.commons.lang3.time.DateFormatUtils.format(user.getBirth(),\"yyyy-MM-dd\"))")
    })
    List<UserDto> userToUserDto(List<User> users);

}
